﻿@using Resources;
@{
    ViewBag.Title = "Upload";
}
@Styles.Render("~/Content/dropzonescss")
@Styles.Render("~/Content/working.css")

<div class="working-container row">
    <div class="working-menu col-md-2 col-sm-3">
        @Html.Partial("_WorkingMenu")
    </div>
    <div class="working-content col-md-10 col-sm-9">
        <header id="page-header">
            <span class="title">@Labels.UploadDocs</span>
        </header>
        <div class="inner-content-wrapper">
            <div class="upload-container">
                <form action="~/Working/SaveUploadedFile" method="post" enctype="multipart/form-data" class="dropzone" id="dropzoneForm">
                    <div class="fallback">
                        <input name="file" type="file" multiple />
                        <input type="submit" value="Upload" />
                    </div>
                </form>
            </div>
            <a href="#" class="upload-docs-btn btn btn-green" disabled="disabled">@Labels.Upload</a>
            <a class="cancel-button cancel-upload-docs" href="/Working/Index">@Labels.Cancel</a>
        </div>
    </div>
</div>


@section scripts{
    @Scripts.Render("~/bundles/dropzonescripts")
    <script type="text/javascript">
        $(document).ready(function () {

            //File Upload response from the server
            var myDropzone = Dropzone.options.dropzoneForm = {
                addRemoveLinks: true,
                dictCancelUpload: "Cancel",
                autoProcessQueue: false,
                init: function () {
                    var submitButton = $(".upload-docs-btn"),
                        myDropzone = this; // closure

                    submitButton.on("click", function () {
                        //alert('');
                        myDropzone.processQueue(); // Tell Dropzone to process all queued files.
                    });

                    // You might want to show the submit button only when
                    // files are dropped here:
                    this.on("addedfile", function () {
                        // Show submit button here and/or inform user to click it.
                        $(".upload-docs-btn").removeAttr('disabled');
                    });

                    this.on("removedfile", function (file) {
                        // Show submit button here and/or inform user to click it.
                        if (myDropzone.files.length == 0) {
                            $(".upload-docs-btn").attr('disabled', 'disabled');
                        }
                    });

                    this.on("maxfilesexceeded", function (data) {
                        var res = eval('(' + data.xhr.responseText + ')');

                    });
                }
            };
        });

    </script>
}